package com.codejiwei.flink.practice;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @author jiwei
 * @description
 * @date 2023/5/19 16:57
 */
public class Flink_Transform_FlatMap {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

//        env.fromElements(1, 2, 3, 4, 5)
//                .flatMap(new FlatMapFunction<Integer, Integer>() {
//                    @Override
//                    public void flatMap(Integer integer, Collector<Integer> collector) throws Exception {
//                        collector.collect(integer * integer);
//                        collector.collect(integer * integer * integer);
//                    }
//                })
//                .print();

        env.fromElements(1, 2, 3, 4, 5)
                .flatMap((Integer value, Collector<Integer> out) -> {
                    out.collect(value * value);
                    out.collect(value * value * value);
                }).returns(Types.INT)
                .print();

        env.execute();
    }
}
